<% filter_sections = [] unless local_assigns.has_key?(:filter_sections) %>
<% search_label = t("decidim.searches.filters.search") unless local_assigns.has_key?(:search_label) %>

<% if filter_sections.present? || local_assigns.has_key?(:search_variable) %>
  <%= filter_form_for filter, url_for, class: "new_filter self-stretch", data: { filters: "", controller: "accordion form-filter" } do |form| %>

    <button id="dropdown-trigger-filters" data-controller="dropdown" data-target="dropdown-menu-filters" data-open-md="true">
      <%= icon "arrow-down-s-line" %>
      <%= icon "arrow-up-s-line" %>
      <span>
        <%= local_assigns.has_key?(:search_variable) ? t("filter_and_search", scope: "decidim.searches.filters_small_view") : t("filter", scope: "decidim.searches.filters_small_view") %>
      </span>
    </button>

    <div id="dropdown-menu-filters">
      <% if local_assigns.has_key?(:skip_to_id) %>
        <%= link_to t("skip", scope: "decidim.shared.filter_form_help"), "##{skip_to_id}", class: "filter-skip", role: "menuitem", "data-skip-to-content": true %>
      <% end %>

      <p id="filter-help-text" class="filter-help" role="menuitem" aria-disabled="true"><%= t("help", scope: "decidim.shared.filter_form_help") %></p>

      <% if local_assigns.has_key?(:search_variable) %>
        <div class="filter-search filter-container" role="menuitem">
          <%= form.search_field search_variable,
                                label: false,
                                placeholder: search_label,
                                title: filter_search_label(search_label, skip_to_id),
                                "aria-label": filter_search_label(search_label, skip_to_id),
                                "aria-describedby": "filter-help-text" %>
          <button type="submit" aria-label="<%= filter_search_label(search_label, skip_to_id) %>">
            <%= icon "search-line" %>
          </button>
        </div>
      <% end %>

      <% filter_sections.each do |f| %>
        <%= form.collection_filter(**f) %>
      <% end %>

      <%= yield %>
    </div>

  <% end %>
<% end %>
